<?php

namespace Home\Controller;
/**
 * 品牌授权
 * @author dem
 *
 */
class TestController  extends HomeController {
    
    function test(){
        $xml = '<ItemRequest>
  <Company>TEST</Company>
  <WareHouse>TEST001</WareHouse>
  <Items>
    <Item>ABC001</Item>
    <Brand>邦威</Brand>
    <Name>T恤</Name>
    <BarCode>690000000001</BarCode>
    <GoodSpec>XL</GoodSpec>
    <Color>黑色</Color>
    <Length>10.00000</Length>
    <Width>15.00000</Width>
    <Height>16.00000</Height>
    <Weight>17.00000</Weight>
    <Unit>EA</Unit>
    <Sprice>20.00000</Sprice>
    <ControlId>N</ControlId>
    <UserDef1>自定义字段1</UserDef1>
    <UserDef2>自定义字段2</UserDef2>
    <UserDef3>自定义字段3</UserDef3>
    <UserDef4>自定义字段4</UserDef4>
  </Items>
</ItemRequest>';
        
        
      /*   print_r((array)simplexml_load_string($xml)); // xml to array
        exit; */
        
        
        $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?>");
        $xml->addChild('ItemRequest');
        var_dump( $xml->asXML());
        exit;
      
        $header[]="Content-Type: text/xml; charset=utf-8";
        $header[]="Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
        $header[]="Connection: keep-alive";
        $header[]="Subject:ItemRequest";
        $header[]="Message-From:TTX";
        $header[]="Content-Length: ".strlen($xml);
        $url = "http://local.query.com/test.php";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $res = curl_exec($ch);
        curl_close($ch);
       // header('Content-Type:text/xml; charset=utf-8');
        echo ($res);
    }
    
    
    function testservice(){
        print_r($_SERVER); //获取header信息
        print_r( $HTTP_RAW_POST_DATA);//获取xml
       
    }
    
    function testcom(){

        $mycomp = new COM("SAPbobsCOM.Company") or die("Cannot start SBO");
        $mycomp->Server="192.168.1.10";
        $mycomp->LicenseServer = "192.168.1.10:30000";
        $mycomp->DBServerType = "6";
        $mycomp->DbUserName = "sa2";
        $mycomp->DbPassword = "sasa";
        $mycomp->UserName = "manager";
        $mycomp->Password = "a10123200";
        $mycomp->CompanyDB = "GT-TEST10";
        $mycomp->Connect;
        
        $oQuotations =$mycomp->GetBusinessObject(20);
        /* $oQuotations->CardCode="D00010";
        $oQuotations->DocDueDate="2013/10/10";
        $oQuotations->UserFields->Fields->Item("U_Ccode")->Value = "C001013";
        $oQuotations->Lines->Itemcode="SY7208ABC";
        $oQuotations->Lines->Price = 0.017;
        $oQuotations->Lines->Currency = "USD";
        $oQuotations->Lines->VatGroup = "X0";
        $oQuotations->Lines->Quantity = 999999999;
        $oQuotations->Lines->UserFields->Fields->Item("U_Sprice")->Value = "C001013";
        $result=$oQuotations->Add(); */
        
        print_r($oQuotations);exit;
    }
    
    function testreturn(){
        $string = <<<XML
<?xml version='1.0' encoding='utf-8'?>
<xml>
</xml>
XML;
        $xml = simplexml_load_string($string);
        $item = $xml->addChild('item');
        $item->addChild('aaaa',222);
        header('Content-Type: text/xml');
        echo $xml->asXML();
        exit;
    }
    
    
}